"""
API数据模型
"""
from typing import List, Dict, Any, Optional
from pydantic import BaseModel, Field


class SearchRequest(BaseModel):
    """搜索请求"""
    query: str = Field(..., description="搜索查询")
    kb_name: str = Field(default="default", description="知识库名称")
    top_k: int = Field(default=3, description="返回结果数量")
    score_threshold: float = Field(default=0.5, description="相似度阈值")


class SearchResponse(BaseModel):
    """搜索响应"""
    success: bool = Field(..., description="是否成功")
    results: List[Dict[str, Any]] = Field(default=[], description="搜索结果")
    total: int = Field(default=0, description="结果总数")
    query: str = Field(..., description="查询内容")
    kb_name: str = Field(..., description="知识库名称")


class AddDocumentRequest(BaseModel):
    """添加文档请求"""
    file_path: str = Field(..., description="文件路径")
    kb_name: str = Field(default="default", description="知识库名称")
    chunk_size: int = Field(default=750, description="文本块大小")
    chunk_overlap: int = Field(default=150, description="重叠长度")
    splitter_name: str = Field(default="ChineseRecursiveTextSplitter", description="分割器名称")


class AddDocumentResponse(BaseModel):
    """添加文档响应"""
    success: bool = Field(..., description="是否成功")
    doc_count: int = Field(default=0, description="文档数量")
    doc_ids: List[str] = Field(default=[], description="文档ID列表")
    file_info: Dict[str, Any] = Field(default={}, description="文件信息")
    error: str = Field(default="", description="错误信息")


class KnowledgeBaseInfo(BaseModel):
    """知识库信息"""
    kb_name: str = Field(..., description="知识库名称")
    vector_store_type: str = Field(..., description="向量存储类型")
    embedding_model: str = Field(..., description="嵌入模型")
    kb_path: str = Field(..., description="知识库路径")
    doc_path: str = Field(..., description="文档路径")
    vs_path: str = Field(..., description="向量存储路径")


class ListKnowledgeBasesResponse(BaseModel):
    """列出知识库响应"""
    success: bool = Field(..., description="是否成功")
    knowledge_bases: List[str] = Field(default=[], description="知识库列表")


class ClearKnowledgeBaseRequest(BaseModel):
    """清空知识库请求"""
    kb_name: str = Field(default="default", description="知识库名称")


class ClearKnowledgeBaseResponse(BaseModel):
    """清空知识库响应"""
    success: bool = Field(..., description="是否成功")
    message: str = Field(default="", description="操作结果")


class HealthCheckResponse(BaseModel):
    """健康检查响应"""
    status: str = Field(default="ok", description="服务状态")
    version: str = Field(default="1.0.0", description="版本号")
    timestamp: str = Field(..., description="时间戳") 